package storage

import (
	. "go-caipu/pkg/services/sqlstore/migrator"
)

func AddFileMetadataMigrations(mg *Migrator) {
	fileMetadata := Table{
		Name: "sys_file_metadata",
		Columns: []*Column{
			{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
			{Name: "file_id", Type: DB_BigInt, Nullable: false, Comment: "关联file_storage.id"},
			{Name: "meta_key", Type: DB_Varchar, Length: 100, Nullable: false, Comment: "元数据键"},
			{Name: "meta_value", Type: DB_Text, Nullable: true, Comment: "元数据值"},
			{Name: "created_at", Type: DB_DateTime, Nullable: false, Default: "CURRENT_TIMESTAMP", Comment: "创建时间"},
			{Name: "updated_at", Type: DB_DateTime, Nullable: false, Default: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", Comment: "更新时间"},
		},
		Indices: []*Index{
			{Cols: []string{"file_id", "meta_key"}, Type: UniqueIndex, Name: "uk_file_meta"},
		},
	}

	// 创建表
	mg.AddMigration("create table sys_file_metadata", NewAddTableMigration(fileMetadata))
	mg.AddMigration("create index uk_file_meta_md5", NewAddIndexMigration(fileMetadata, fileMetadata.Indices[0]))
}
